<template>
  <div class="full">
    <div class="g-reg-wrap">
      <div class="m-reg-cet">
        <div class="m-reg-header">
          <p class="back">
            <router-link to="/">首页</router-link>
          </p>
          <p class="logo"><img src="../images/logo.png" width="147" height="76"/></p>
        </div>


        <!-- S 登录-->
        <div class="m-regbox">
          <div class="hd"></div>

          <div class="bd">
            <h2 class="reg-tit">登录</h2>
            <div class="m-formlist">
              <ul class="clearfix">
                <li>
                  <input v-model="mobile" class="int" type="text" name="" value="" placeholder="请输入手机号"/>
                </li>
                <li>
                  <input v-model="password" class="int" type="password" name="" value="" placeholder="请输入密码"/>
                </li>
              </ul>
              <p class="linkbtn clearfix">
                <a class="lb1" href="#">立即注册</a>
                <a class="lb2" href="#">忘记密码？</a>
              </p>
              <p class="btn">
                <a v-on:click="login">登录</a>
              </p>
            </div>
          </div>
        </div>
        <!-- E 登录-->


      </div>

    </div>
  </div>
</template>

<script>
  export default {
    name: "login",
    data() {
      return {
        mobile: '',
        password: '',
      }
    }, methods: {

      login() {
        let params = {
          'mobile': this.mobile,
          'password': this.password
        }
        this.$post('/user/login', params).then(response => {
          this.$check(response)

          let user = {
            'token': response.data.token
          }
          this.$store.dispatch('login', user)
          let userId = response.data.userId
          this.$fetch('/user/getBaseUserInfo?userId=' + response.data.userId).then(response => {
            this.$check(response)

            let user = {
              'username': response.data.nickname,
              'photo': response.data.picUrl,
              'userId': userId,
            }
            this.$store.dispatch('updateUserInfo', user)
          });


          window.location.href = '/#/'

        })
      }
    }
  }
</script>

<style scoped>
  .full {
    background: #64abe1;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
  }

</style>
